<?php

/**
 * @author huulienketweb
 * @copyright 2012
 */

 if(!$_SESSION['loged']){
         header('LOCATION: index.php?module=canbo&act=login');  
         exit();
 }
include('controller/c_thongke.php');     
include ('model/m_lienketweb.php');
$page = $_GET['act'];
 switch($page){
    case 'list':
    //Get language
    require('language/lienketweb/list.php');
    $heading_title = heading_title;
    $title = heading_title;
    $button_add = button_add;
    $button_edit = button_edit;
    $button_delete = button_delete;
    
    $malienketweb = ma_lien_ket_web;
    $tenlienketweb = ten_lien_ket_web;
    $diachilienket = dia_chi_lien_ket;
    $thao_tac = thao_tac;
    $link_add ='index.php?module=lienketweb&act=add';
    
    if($_POST['selected']==""){
        $err['exist'] = chua_chon;
        $error_name = $err['exist'];
        }
    if(!$err){
        $valid = true;    
    }
    else{
        $valid = false;
    }
    //kiem tra du lieu cua from
    if(($_SERVER['REQUEST_METHOD']=='POST')&&$valid){
      foreach($_POST['selected'] as $id){
        dellienketweb($id);
      }  
    $_SESSION['success'] = del_success;
    //chuyen huong ve list
    header('LOCATION: '.$link_list);
     }
 
    
           //phan trang
            // kiem tra bien pages
            if($_REQUEST['page']==""){
               $page = 1;
            }
            else{
                
               $page = $_REQUEST['page'];
             
            }
            //get input for class page
            $limit = 5;
            $start = ($page - 1) * $limit;
         
            $list_lienketweb = getListlienketweb($start,$limit);
            //$danhsachdiaphuong = getAll($start,$limit);
            $total = totallkw();
            // paging
            $paging = new Pagination();
            $paging->total = $total;
            $paging->limit = $limit;
            $paging->url = "index.php?module=lienketweb&act=list&page={page}";
            $paging->page = $page;
            $pagination = $paging->render();
            //end phan trang by liem
    
    
    
    require('view/template/lienketweb/list.tpl');
    break;
	
	//case them chuc danh
	case 'add':
	require('language/lienketweb/add.php');
	$heading_title = heading_title;
    $ma_lienketweb = ma_lien_ket_web;
	$ten_lienketweb = ten_lien_ket_web;
    $diachilienket = dia_chi_lien_ket;
    $link_list = 'index.php?module=lienketweb&act=list';
    
    if($_POST['ten_lien_ket_web']==""){
        $err['exist'] = chua_nhap_ten;
        $error_name = $err['exist'];
             }
    if(!$err){
        $valid = true;    
    }
    else{
        $valid = false;
    }
    if(($_SERVER['REQUEST_METHOD']=='POST')&&$valid)
    {
    insertlienketweb($_POST);
    $_SESSION['success'] = edit_success;
    //chuyen huong ve list
    header('LOCATION: '.$link_list);    
    }
    require('view/template/lienketweb/add.tpl');
    break;
    
    //case sua dan toc
    case 'edit':
    require('language/lienketweb/edit.php');
    $heading_title = heading_title;
    $title = heading_title;
    $ma_lienketweb = ma_lien_ket_web;
    $ten_lienketweb = ten_lien_ket_web;
    $diachilienket = dia_chi_lien_ket;
    $link_list = 'index.php?module=lienketweb&act=list';
    $id = $_REQUEST['id'];
    $lienketweb = getlienketweb($id);
    
    if($_SERVER['REQUEST_METHOD']=='POST')
    {
    editlienketweb($id, $_POST);
    $_SESSION['success'] = edit_success;
    //chuyen huong ve list
    header('LOCATION: '.$link_list);    
    }
        
    
    require('view/template/lienketweb/edit.tpl');
    break; 
    
  
}




?>